package com.example.spareparts.repository;

import org.apache.ibatis.annotations.*;
import com.example.spareparts.entity.SparePart;

import java.util.List;

@Mapper
public interface SparePartRepository  {
    @Select("SELECT * FROM SpareParts")
    List<SparePart> findAllSparePart();
    @Insert("INSERT INTO SpareParts (model, specification, supplier_id) VALUES (#{model}, #{specification}, #{supplierid})")
    @Options(useGeneratedKeys = true, keyProperty = "sparepartid")
    void insertSparePart(SparePart sparePart);
    @Update("UPDATE SpareParts SET model= #{model}, specification= #{specification}, supplier_id= #{supplierid} WHERE spare_part_id= #{sparepartid}")
    void updateSparePart(SparePart sparePart);
    @Delete("DELETE FROM SpareParts WHERE spare_part_id= #{sparepartid}")
    void deleteSparePart(Long sparepartid);
    @Select("SELECT * FROM SpareParts WHERE spare_part_id= #{sparepartid}")
    SparePart findSparePartById(Long sparepartid);

    @Select("SELECT * FROM SpareParts WHERE supplier_id= #{supplierid}")
    List<SparePart> findSparePartBySupplierId(Long supplierid);

}